perm filename PMOVE.2[EAL,HE] blob sn#676480 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00004 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	{$NOMAIN	MOVE statement parser }
C00025 00003	{ Externally defined routines from elsewhere: }
C00028 00004	function moveParse(st: statementp): boolean external
C00053 ENDMK
C⊗;
{$NOMAIN	MOVE statement parser }

const

  (* Constants from EDIT; need these for the constants section *)
  maxLines = 28;        (* smaller on the 11 than on the 10 *)
  maxPPLines = 18;
  maxBpts = 25;
  maxTBpts = 20;  	(* max could be exceeded by huge case stmnt *)
  listinglength = 2000; (* Length of Listingarray *)

(* Random type declarations for OMSI/SAIL compatibility *)

type

  byte = 0..255;	(* doesn't really belong here, but... *)
  ascii = char; 
  atext = text;

{ Define all the pointer types here }

vectorp = ↑vector;
strngp = ↑strng;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;

(* This one is used whenever a pointer is needed for which the definition
 	is missing from this file; naturally, all pointers use the same space *)

dump = ↑integer;
cursorp = array[1..4] of integer;

(* datatype definitions *)

datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
	     frametype, eventtype, strngtype, labeltype, proctype, arraytype,
	     reftype, valtype, cmontype, nulltype, undeftype,
	     dimensiontype, mactype, macargtype, freevartype);

scalar = real;

u = (used,free);
vector = record case u of
	   used: (refcnt: integer; val: array [1..3] of real);
	   free: (next: vectorp);
	 end;

cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;

strng = record
	  next: strngp;
	  ch: cstring;
	end;


(* statement definitions *)

stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
		fortype, iftype, whiletype, untiltype, casetype,
		calltype, returntype,
		printtype, prompttype, pausetype, aborttype, assigntype,
		signaltype, waittype, enabletype, disabletype, cmtype,
		affixtype, unfixtype,
		movetype, operatetype, opentype, closetype, centertype,
		stoptype, retrytype,
		requiretype, definetype, macrotype, commenttype, dimdeftype,
		setbasetype, wristtype, tovaltype, declaretype, emptytype);
		(* more??? *)

statement = packed record
		next, last: statementp; (* ↑ to lexical tokens? *)
		stlab: varidefp;
		exprs: nodep;	(* any expressions used by this statement *)
		nlines: integer;
		bpt: boolean;
		case stype: stmntypes of

    blocktype,
    declaretype,
    endtype,
    coendtype:	    (bcode, bparent: statementp; blkid: identp;
			level, numvars: 0..255; variables: varidefp);
    affixtype,
    unfixtype:	    (frame1, frame2, byvar, atexp: nodep; rigid: boolean);
    cmtype:	    (oncond: nodep; conclusion: statementp;
			deferCm, exprCm: boolean; cdef: varidefp);
    movetype,
    operatetype,
    opentype,
    closetype,
    centertype,
    stoptype:	    (cf, clauses: nodep);
    retrytype:	    (rcode, rparent: statementp; olevel: integer);
    signaltype,
    waittype:	    (event: nodep);
    enabletype,
    disabletype:    (cmonlab: varidefp);
		end;

(* auxiliary definitions: variable, etc. *)

varidef = packed record
	    next,dnext: varidefp;
	    name: identp;
	    level: 0..255;	(* environment level *)
	    offset: 0..255;	(* environment offset *)
	    dtype: varidefp;	(* to hold the dimension info *)
	    tbits: 0..15;  (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
	    dbits: 0..15;	(* for use by debugger/interpreter *)
	    case vtype: datatypes of
  arraytype:  (a: nodep);
  proctype:   (p: nodep);
  labeltype,
  cmontype:   (s: statementp);
  mactype:    (mdef: statementp);
  macargtype: (marg: tokenp);
  pconstype:  (c: nodep);
  dimensiontype: (dim: nodep);
	  end;

(* definition of the ubiquitous NODE record *)

nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
		deprnode, viaptnode, apprnode, destnode, durnode,
		sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
		arrivalnode, departingnode,
		ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
		calcnode, arraydefnode, bnddefnode, bndvalnode,
		waitlistnode, procdefnode, tlistnode, dimnode, commentnode);

exprtypes =  (	svalop,					(* scalar operators *)
		sltop, sleop, seqop, sgeop, sgtop, sneop,	(* relations *)
		notop, orop, xorop, andop, eqvop,		(* logical *)
		saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
		sexpop, maxop, minop, intop, idivop, modop,
		sqrtop, logop, expop, timeop,			(* functions *)
		sinop, cosop, tanop, asinop, acosop, atan2op,	(* trig *)
		vdotop, vmagnop, tmagnop,
		vecop,					(* vector operators *)
		vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
		svmulop, vsmulop, vsdivop, tvmulop, wrtop,
		tposop, taxisop,
		transop,				(* trans operators *)
		tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
		vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
		ioop,					(* i/o operators *)
		queryop, inscalarop,
		specop,					(* special operators *)
		arefop, callop, grinchop, macroop, vmop, adcop, dacop,
		badop,
		addop, subop, negop, mulop, divop, absop); (* for parsing *)

leaftypes = pconstype..strngtype;

reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);

node = record
	next: nodep;
	case ntype: nodetypes of
    exprnode:	(op: exprtypes; arg1, arg2, arg3: nodep; elength: integer);
    leafnode:	(case ltype: leaftypes of
	varitype:  (vari: varidefp; vid: identp);
	pconstype: (cname: varidefp; pcval: nodep);
	svaltype:  (s: scalar; wid: integer);
	vectype:   (v: vectorp);
	transtype: (t: dump);
	strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
    listnode:	(lval: nodep);
    clistnode:	(cval: integer; stmnt: statementp; clast: nodep);
    colistnode:	(prev: nodep; cstmnt: statementp);
    forvalnode:	(fvar: dump; fstep: scalar);	{dummy}
    arrivalnode:(evar: varidefp);
    deprnode,
    apprnode,
    destnode:	(loc: nodep; code: statementp);
    viaptnode:	(vlist: boolean; via,duration,velocity: nodep; vcode: statementp);
    durnode:	(durrel: reltypes; durval: nodep);
    sfacnode,
    wobblenode,
    swtnode:	(clval: nodep);
    nullingnode,
    wristnode,
    cwnode:	(notp: boolean); (* true = nonulling/zero wrist/counter_clockwise *)
    ffnode:	(ff: nodep; csys, pdef: boolean); (* true = world, false = hand *)
    forcenode:	(ftype: forcetypes; frel: reltypes; fval, fvec, fframe: nodep);
    stiffnode:	(fv, mv, coc: nodep);
    gathernode:	(gbits: integer);
    cmonnode:	(cmon: statementp; errhandlerp: boolean);
    errornode:	(eexpr: nodep);
    calcnode: 	(rigid, frame1: boolean; other: dump; case tvarp: boolean of 
		    false: (tval: dump); true: (tvar: dump) );	{dummy}
    arraydefnode: (numdims: 1..10; bounds: nodep; combnds: boolean);
    bnddefnode:	(lower, upper: nodep);
    bndvalnode:	(lb, ub, mult: integer);
    waitlistnode: (who: dump; when: integer);
    procdefnode:(ptype: datatypes; level: 0..255;
		    pname, paramlist: varidefp; body: statementp);
    tlistnode:	(tok: tokenp);
    dimnode:	(time, distance, angle, dforce: integer);
	end;

(* records for parser: ident, token, resword *)

ident = record
	    next: identp;
	    length: integer;
	    name: strngp;
	    predefined: varidefp;
	  end;


tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
		macpartype);

constypes = svaltype..strngtype;

reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);

filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
		errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
		sourcefiletype,steptype,thentype,totype,untltype,viatype,
		withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
		ontype,offtype,ppsizetype,collecttype,alltype,lextype);

clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
		errortype,forcetype,forceframetype,forcewristtype,gathertype,
		nildeproachtype,nonullingtype,nullingtype,stiffnesstype,
		torquetype,velocitytype,wobbletype,
		cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
		fxtype,fytype,fztype,mxtype,mytype,mztype,
		t1type,t2type,t3type,t4type,t5type,t6type,tbltype);

edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
		stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
		breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
		popcmd);

token = record
	  next: tokenp;
	  case ttype: tokentypes of
constype:   (cons: nodep);
comnttype:  (len: integer; str: strngp);
delimtype:  (ch: ascii);
reswdtype:  (case rtype: reswdtypes of
	stmnttype: (stmnt: stmntypes);
	filtype:   (filler: filtypes);
	clsetype:  (clause: clsetypes);
	decltype:  (decl: datatypes);
	optype:	   (op: exprtypes);
	edittype:  (ed: edittypes) );
identtype:  (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
	end;


(* Global variables *)

var 
	(* From ALMAIN *)
    b:boolean;		
    ch:ascii;
    ltime: real;

	(* From PARSE *)
    reswords: array [0..26] of dump;
    idents: array [0..26] of identp;
    macrostack: array [1..10] of tokenp;
    curmacstack: array [1..10] of varidefp;
    macrodepth: integer;
    curchar, maxchar, curline: integer;
    curBlock,newDeclarations: statementp;
    curProc: varidefp;
    pnode: nodep;
    nodim, distancedim, timedim, angledim,
      forcedim, torquedim, veldim, angveldim: varidefp;
    fvstiffdim, mvstiffdim: nodep;
    filedepth: integer;
    curpage: integer;
    sysVars,unVars: varidefp;
    errcount: integer;
    outerBlock: statementp;
    curVariable: varidefp;
    curMotion: statementp;
    endOk,coendOk: integer;
    moveLevel: integer;
    curErrhandler, curCmon: statementp;
    endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
    semiseen, shownline: boolean;
    eofError: boolean;
    inMove,inCoblock: boolean;
    curtoken: token;
    file1,file2,file3,file4,file5: atext;
    line: linestr;

	(* From INTERP *)
(*  curInt, activeInts, readQueue, allPdbs: pdbp;
    curEnv, sysEnv: envheaderp;
    clkQueue: nodep;
    allEvents: dump;
    STLevel: integer;	
    etime: integer;	
    curtime: integer; 	
    stime: integer;	
    msg: messagep;	
    inputp: integer;	
    debugLevel: integer;	*)
    d1: array[1..15] of dump;
    tSingleThreadMode: boolean;
    resched, running, escapeI, singleThreadMode: boolean;
    msgp: boolean;		(* flag set if any messages pending *)
    inputReady: boolean;
    inputLine: array [1..20] of ascii;

	(* From EDIT *)
    lines: array [1..maxLines] of dump; 
    ppLines: array [1..maxPPLines] of dump;	
    marks: array [1..20] of integer;
    cursorStack: array [1..15] of cursorp;
    bpts: array [1..maxBpts] of statementp;
    tbpts: array [1..maxTBpts] of statementp;
    debugPdbs: array [0..10] of dump;
    screenheight,dispHeight: integer;
    ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
    lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
    firstDline,topDline,botDline,firstLine,lastLine: integer;
    freeLines,oldLines: dump;
    findStmnt: statementp;
    nbpts,ntbpts: integer;
    eCurInt: dump;
    dProg: statementp;	
    smartTerminal: boolean; 
    setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
    eBackup: boolean;			
    eSingleThreadMode: boolean;	
    listing: packed array [0..listinglength] of ascii;
    lbuf: array [1..160] of ascii;
    ppBuf: array [1..100] of ascii;
    outFile: atext;
    eCurToken: token;			

	(* Various device & variable pointers *)
    speedfactor: dump;
    barm: dump;

	(* Various constant pointers *)
    xhat,yhat,zhat,nilvect: vectorp;
    niltrans: dump;
    bpark, ypark, gpark, rpark: dump;		(* arm park positions *)

{ Externally defined routines from elsewhere: }

	(* From ALLOC *)
function newNode: nodep;					external;
procedure relNode(n: nodep);					external;
function newStatement: statementp;				external;

	(* From PROOT *)
procedure errprnt;						external;
procedure getToken;						external;
procedure ppFlush;						external;
function mvExprParse: nodep;					external;
function mvThencode(evp: boolean): statementp;			external;
function mvClauseParse(absSeen: boolean): nodep;		external;
function mvCmonParse(st: statementp; deferred: boolean): boolean; external;

	(* From PAUX1 *)
function checkArg(n: nodep; d: datatypes): nodep;		external;

	(* From PAUX2 *)
function evalOrder(what,last: nodep; pcons: boolean): nodep;	external;
procedure checkdim(n,d: nodep);					external;

	(* Display-related Routines *)
procedure ppLine; 						external;
procedure ppOutNow; 						external;
procedure ppChar(ch: ascii); 					external;
procedure pp5(ch: c5str; length: integer); 			external;
procedure pp10(ch: cstring; length: integer); 			external;
procedure pp10L(ch: cstring; length: integer);			external;
procedure pp20(ch: c20str; length: integer); 			external;
procedure pp20L(ch: c20str; length: integer); 			external;
procedure ppInt(i: integer); 					external;
procedure ppReal(r: real); 					external;
procedure ppStrng(length: integer; s: strngp); 			external;

procedure pMoveGet; external;
procedure pMoveGet;	begin end;
function moveParse(st: statementp): boolean; external;
function moveParse;
 var b, done, vp, oldInMove, movep, operatep, centerp, openp, arrp: boolean;
     lastclause, cl, lexpr: nodep;
     via, dest, appr, depr, wobble, sfac, dur, vel, torquecl: nodep;
     oldmotion, lastcmon: statementp;
     clab: varidefp; oldMoveLevel, useForce, cmForce: integer;
     gathering, zwrist, notaxis: boolean; stiff, ffr, fn1: nodep;

 procedure addClause(cl: nodep);
  begin
  if cl <> nil then			(* make sure it was ok *)
   begin
   if lastclause <> nil then		(* add it to clause list *)
     lastclause↑.next := cl
    else st↑.clauses := cl;		(* first clause seen *)
   lastclause := cl;
   cl↑.next := nil;
   end;
  end;

 procedure ffcompare(ff2: nodep);
  var b: boolean; v1,v2: varidefp;
  begin
  if ff2 <> nil then
   if ffr = nil then ffr := ff2		(* remember first force frame we see *)
    else
     begin				(* see if they match *)
     b := ffr↑.csys = ff2↑.csys;	(* make sure they use same coord sys *)
     v1 := nil;
     v2 := nil;
     with ffr↑.ff↑ do
      if ntype = leafnode then
	if ltype = pconstype then v1 := cname
	 else if ltype = varitype then v1 := vari else b := false
       else if (ntype = exprnode) and (op = arefop) then v1 := arg1↑.vari
       else b := false;
     with ff2↑.ff↑ do
      if ntype = leafnode then
	if ltype = pconstype then v2 := cname
	 else if ltype = varitype then v2 := vari else b := false
       else if (ntype = exprnode) and (op = arefop) then v2 := arg1↑.vari
       else b := false;
     if not (b or (v1 = v2)) then
       begin
       pp20L('MOVE statement has m',20); pp20('ultiply defined forc',20);
       pp10('e frames  ',8);
       errprnt;
       end;
     end;
  end;

 procedure fcheck(fn: nodep);			(* check force axis is ok *)
  var vec: vectorp; 

  procedure badvector(fn: nodep);		(* axis error *)
   var bad: nodep;
   begin
   pp20L('force direction must',20); pp20(' be along an axis - ',20);
   pp20('assuming zhat       ',13);
   errprnt;					(* not right line, but... *)
   bad := newNode;
   with bad↑ do
     begin
     ntype := exprnode;
     op := badop;
     arg1 := fn↑.fvec;
     arg2 := newNode;
     end;
   with bad↑.arg2↑ do
     begin ntype := leafnode; ltype := vectype; v := zhat end;
   fn↑.fvec := bad;
   end;

  begin {fcheck}	(* note: can't really check variables or expressions *)
  ffcompare(fn↑.fframe);		(* first check its force frame *)
  if (useForce + cmForce > 1) and notaxis then
    begin			(* first force spec was bad - fix it now *)
    pp20L('In previous force sp',20); pp20('ecification:        ',12);
    badvector(fn1);
    end;
  vec := nil;
  with fn↑.fvec↑ do
   if ntype = leafnode then vec := pcval↑.v	(* first check if axis vector *)
   else if op = vnegop then 			(* or negative axis vector *)
    if arg1↑.ntype = leafnode then vec := arg1↑.pcval↑.v;
  if not((vec = xhat) or (vec = yhat) or (vec = zhat)) then
   if useForce + cmForce = 1 then
     begin					(* single sense/apply *)
     fn1 := fn;
     notaxis := true;		(* remember that it's not along an axis *)
     end
    else badvector(fn);				(* multiple axes - error *)
  end {fcheck};

 procedure addCmon(clab: varidefp; deferred: boolean);
  var cst: statementp; cl: nodep; bad: boolean;
  begin
  bad := false;
  if (clab <> nil) or deferred then	(* need to check for "ON" *)
   begin
   getToken;
   with curToken do
    if (ttype <> reswdtype) or (rtype <> stmnttype) or (stmnt <> cmtype) then
     begin
     bad := true;
     backup := true;
     pp20L('Expected an "ON" her',20); ppChar('e');
     errprnt;
     end;
   end;
  if not bad then
   begin
   cst := newStatement;
   with cst↑ do
    begin
    stype := cmtype;
    stlab := clab;
    if clab <> nil then clab↑.s := cst;		(* define the label *)
    end;
   bad := mvCmonParse(cst,deferred);	(* if it's bad we should flush it, but... *)
   with cst↑.oncond↑ do
    if ntype = forcenode then
      begin
      cmForce := cmForce + 1;
      if movep then fcheck(cst↑.oncond);
      end
     else if ntype = arrivalnode then
      begin
      if arrp then
	begin
	pp20L('Can only specify one',20); pp20(' "ON ARRIVAL DO" for',20);
	pp10(' a motion!',10);
	errprnt;
	end;
      arrp := true;
      end;
   cl := newNode;
   with cl↑ do
    begin
    ntype := cmonnode;
    cmon := cst;
    errHandlerp := cst↑.oncond↑.ntype = errornode;
    if errHandlerp then		(* point back to motion statement, not cmon *)
      cst↑.conclusion↑.next↑.bparent := st;
    end;
   addClause(cl);
   end;
  end;

 begin	{moveParse}			(* move statement *)
 b := false;
 oldmotion := curMotion;		(* remember previous motion statement *)
 curMotion := st;			(* remember this motion *)
 oldInMove := inMove;
 inMove := true;
 oldMoveLevel := moveLevel;		(* remember our lex level for retry *)
 if curBlock <> nil then moveLevel := curBlock↑.level else moveLevel := 0;
 arrp := false;
 movep := false;
 operatep := false;
 centerp := false;
 openp := false;
 with st↑, curToken do
  begin
  if stype = movetype then movep := true
   else if stype = operatetype then operatep := true
   else if stype = centertype then centerp := true else openp := true;
  if movep or centerp then
    cf := checkarg(mvExprParse,frametype)		(* what are we moving? *)
   else cf := checkarg(mvExprParse,svaltype);
  with cf↑ do					(* make sure it's a variable *)
   begin
   b := (ntype <> leafnode) or (ltype <> varitype);
   if b then b := (ntype <> exprnode) or (op <> arefop);
   if not b then			(* ok so far, check some more *)
    if centerp then
     begin					(* check for arms *)
     if ntype <> leafnode then b := true
      else b := (vari↑.level <> 0) or not (vari↑.offset in [0,4,8,12]);
	(* offsets: 0=barm, 4=yarm, 8=garm, 12=rarm *)
     end
    else if operatep then
     begin					(* check for driver *)
     if ntype <> leafnode then b := true
      else b := (vari↑.level <> 0) or (vari↑.offset <> 16);
	(* offset: 16=driver *)
     end
    else if openp then
     begin					(* check for scalar devices *)
     if ntype <> leafnode then b := true
      else b := (vari↑.level <> 0) or not (vari↑.offset in [2,6,10,14,20]);
	(* offsets: 2=bhand, 6=yhand, 10=ghand, 14=rhand, 20=vise *)
     end;
   end;
  if b then
    begin
    pp20L('Need a device variab',20); pp10('le here.  ',8); ppFlush;
    errprnt;
    end;
  clauses := nil;
  lastclause := nil;
  lastcmon := nil;
  dest := nil;
  appr := nil;
  depr := nil;
  wobble := nil;
  sfac := nil;
  dur := nil;
  useForce := 0;
  cmForce := 0;
  stiff := nil;
  gathering := false;
  ffr := nil;
  fn1 := nil;
  notaxis := false;
  done := false;
  repeat			(* get all the clauses *)
   flushcomments := false;		(* comments are ok here *)
   getToken;
   flushcomments := true;		(* but not inside other clauses *)
   if (ttype = reswdtype) and (rtype = filtype) then	(* TO, VIA, WITH *)
     begin
     if filler = totype then	(* get destination *)
       begin
       if dest <> nil then
	begin
	pp20L('Can only specify one',20); pp20(' destination for a m',20);
	pp10('otion!    ',6);
	errprnt;
	end;
       dest := newNode;
       with dest↑ do
	begin
	ntype := destnode;
	if movep then loc := checkarg(mvExprParse,transtype)
	 else loc := checkarg(mvExprParse,svaltype);
	checkdim(loc,distancedim↑.dim);
	code := nil;
	end;
       addClause(dest);
       end
      else if filler = viatype then	(* get VIA point(s) *)
       begin		(* ** maybe should check that this is a MOVE stmnt ** *)
       repeat
	via := newNode;
	addClause(via);
	with via↑ do
	 begin
	 ntype := viaptnode;
	 vlist := ttype = delimtype;	(* part of a via list or not *)
	 via := checkarg(mvExprParse,transtype);
	 checkdim(via,distancedim↑.dim);
	 velocity := nil;
	 duration := nil;
	 vcode := nil;
	 getToken;
	 if (ttype = reswdtype) and
	    (rtype = filtype) and (filler = wheretype) then
	   begin
	   vp := true;
	   while vp do
	    begin		(* look for velocity & duration specs *)
	    getToken;
	    if (ttype = reswdtype) and
	       (rtype = clsetype) and (clause = velocitytype) then
	      begin
	      getToken;		(* skip over the '=' *)
	      velocity := checkarg(mvExprParse,vectype);
	      checkdim(velocity,veldim↑.dim);
	      end
	    else if (ttype = reswdtype) and
		    (rtype = clsetype) and (clause = durationtype) then
	      begin
	      backup := true;
	      duration := mvClauseParse(false);	(* go get the duration spec *)
	      end
	    else if (ttype <> delimtype) or (ch <> ',') then
	      begin backup := true; vp := false; end;
	    end;
	   end;
	 if (ttype = reswdtype) and
	    (rtype = filtype) and (filler = thentype) then
	   begin
	   backup := false;
	   vcode := mvThenCode(true);
	   getToken;
	   end;
	 end
       until (via↑.vcode <> nil) or (ttype <> delimtype) or (ch <> ',');
       backup := true;
       end
      else if filler = withtype then	(* get WITH clause *)
       begin
       addClause(mvClauseParse(false));
       with lastclause↑ do
	if ntype = gathernode then gathering := true
	 else if ntype = wristnode then zwrist := true
	 else if ntype = stiffnode then stiff := lastclause
	 else if ntype = wobblenode then wobble := lastclause
	 else if ntype = sfacnode then sfac := lastclause
	 else if ntype = durnode then dur := lastclause
	 else if (ntype = apprnode) and (loc <> nil) then appr := lastclause
	 else if (ntype = deprnode) and (loc <> nil) then depr := lastclause
	 else if ntype = ffnode then ffcompare(lastclause)
	 else if ntype = forcenode then
	  begin
	  useForce := useForce + 1;
	  if movep then fcheck(lastclause);
	  end;
       end
      else if filler = defertype then	(* deferred cmon *)
       begin
       addCmon(nil,true);
       end
      else				(* unknown clause or we're done *)
       begin done := true; backup := true end
     end
    else if ttype = labeldeftype then
     begin				(* a label *)
     clab := lab;			(* remember it *)
     getToken;
     if (ttype = reswdtype) and (rtype = filtype) and (filler = defertype) then
       addCmon(clab,true)		(* labelled deferred cmon *)
      else
       begin
       backup := true;
       addCmon(clab,false);		(* labelled cmon *)
       end;
     end
    else if (ttype = reswdtype) and (rtype = stmnttype) and (stmnt = cmtype) then
     begin
     addCmon(nil,false);			(* condition monitor *)
     end
    else if (ttype = reswdtype) and (rtype = clsetype) and
	    ((clause = cwtype) or (clause = ccwtype)) then
     begin
     backup := true;
     addClause(mvClauseParse(false));
     end
    else if ttype = comnttype then
     begin
     cl := newNode;
     cl↑.ntype := commentnode;
     cl↑.length := len;				(* copy comment *)
     cl↑.str := str;
     addClause(cl);
     end
    else				(* that's all for this MOVE *)
     begin done := true; backup := true end
  until done;

  if dest = nil then
    begin
(*  if movep or (openp and (cf↑.vari↑.offset <= 6)) then *)
    if movep then
     begin
     pp20L('Need a destination f',20); pp20('or motion statement!',20);
     errprnt;
     end
    end;

  if notaxis and (useForce + cmForce = 1) then
    begin					(* single sense/apply *)
    if ffr <> nil then
      begin
      pp20L('Can''t specify a forc',20); pp20('e frame with a rando',20);
      pp20('m force vector      ',14);
      errprnt;
      end;
    ffr := newNode;			(* make up a new force frame *)
    with ffr↑ do
     begin
     ntype := ffnode;
     ff := newNode;
     with ff↑ do		
      ntype := exprnode;
      op := vmkfrcop;		(* need to compute force frame *)
      arg1 := fn1↑.fvec;
      arg2 := nil;
      arg3 := nil;
      end;
     csys := true;		(* use world coords *)
     pdef := true;
     end;
    addClause(ffr);
    end;

(* now set up those expressions that need to be evaluated for this motion *)

  lexpr := nil;
  if cf <> nil then				(* evaluate control frame *)
   if cf↑.ntype <> leafnode then
     lexpr := evalOrder(cf↑.arg2,nil,true);	(* push array subscripts *)

  if (sfac <> nil) and (dest <> nil) then	(* evaluate speed factor *)
   lexpr := evalOrder(sfac↑.clval,lexpr,false);
  if dur <> nil then			(* evaluate global time duration *)
   lexpr := evalOrder(dur↑.durval,lexpr,false);

  if movep then
    begin				(* MOVE statement has extra clauses *)
    if wobble <> nil then			(* evaluate wobble *)
     lexpr := evalOrder(wobble↑.clval,lexpr,false);
    if ffr <> nil then				(* evaluate force frame *)
     lexpr := evalOrder(ffr↑.ff,lexpr,false);
    if stiff <> nil then			(* deal with stiffness *)
     begin
     lexpr := evalOrder(stiff↑.fv,lexpr,false);	(* evaluate force vector *)
     lexpr := evalOrder(stiff↑.mv,lexpr,false);	(* evaluate torque vector *)
     if stiff↑.coc <> nil then		(* evaluate center of compliance *)
      lexpr := evalOrder(stiff↑.coc,lexpr,false);
     end;
    cl := clauses;
    while cl <> nil do				(* run through clauses *)
     begin
     if cl↑.ntype = forcenode then		(* evaluate bias force values *)
      lexpr := evalOrder(cl↑.fval,lexpr,false);
     cl := cl↑.next;
     end;
    if depr <> nil then				(* evaluate departure *)
     lexpr := evalOrder(depr,lexpr,false);
    cl := clauses;
    while cl <> nil do				(* run through clauses *)
     begin
     if cl↑.ntype = viaptnode then		(* evaluate via points *)
      lexpr := evalOrder(cl,lexpr,false);
     cl := cl↑.next;
     end;
    if appr <> nil then				(* evaluate approach *)
     lexpr := evalOrder(appr,lexpr,false);
    end
   else if operatep then
    begin					(* handle OPERATE *)
    torquecl := nil;
    vel := nil;
    cl := clauses;
    while cl <> nil do				(* run through clauses *)
     with cl↑ do
      begin
      if ntype = forcenode then
	if ftype = torque then torquecl := cl
	 else if ftype = angvelocity then vel := cl;
      cl := next;
      end;
    if vel <> nil then 				(* evaluate angular velocity *)
     lexpr := evalOrder(vel↑.fval,lexpr,false);
    if torquecl <> nil then 				(* evaluate torque *)
     lexpr := evalOrder(torquecl↑.fval,lexpr,false);
    end
   else if openp then
    begin					(* handle OPEN/CLOSE *)
    cl := clauses;
    while cl <> nil do				(* run through clauses *)
     begin
     if cl↑.ntype = swtnode then	(* evaluate stop wait time for vise *)
       begin
       lexpr := evalOrder(cl↑.clval,lexpr,false);
       cl := nil;
       end
      else cl := cl↑.next;
     end;

    end;

  if dest <> nil then				(* evaluate destination *)
   lexpr := evalOrder(dest,lexpr,false);

  cl := clauses;
  while cl <> nil do				(* run through clauses *)
   with cl↑ do
    begin
    if (ntype = cmonnode) and errHandlerp then	(* evaluate error conds *)
      lexpr := evalOrder(cmon↑.oncond↑.eexpr,lexpr,false);
    cl := next;
    end;

  exprs := lexpr;

  end;
 curMotion := oldmotion;		(* restore previous motion statement *)
 inMove := oldInMove;
 moveLevel := oldMoveLevel;
 moveParse := b;
 end;